package com.wgworkshop.pems.controller;

import com.wgworkshop.pems.checkgroup.CreateCheckGroup;
import com.wgworkshop.pems.common.ResponseData;
import com.wgworkshop.pems.model.ClassArrangeModel;
import com.wgworkshop.pems.service.ClassArrangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 班级安排控制器。
 * Created by wlc on 2017/10/11.
 */
@RestController
@RequestMapping("/class-arranges")
public class ClassArrangeController {
    @Autowired
    private ClassArrangeService classArrangeService;

    @PostMapping
    ResponseData<ClassArrangeModel> create(@RequestBody @Validated(CreateCheckGroup.class) ClassArrangeModel classArrangeModel) {
        ClassArrangeModel resultModel = classArrangeService.save(classArrangeModel);
        return new ResponseData<ClassArrangeModel>().success(resultModel);
    }

    @PostMapping("/all")
    ResponseData<List<ClassArrangeModel>> createAll(@RequestBody @Validated(CreateCheckGroup.class) List<ClassArrangeModel> classArrangeModels) {
        List<ClassArrangeModel> resultModels = classArrangeService.saveAll(classArrangeModels);
        return new ResponseData<List<ClassArrangeModel>>().success(resultModels);
    }
}
